package cn.yh.springbootjwt.controller;

import cn.yh.springbootjwt.common.AjaxResult;
import cn.yh.springbootjwt.controller.base.BaseController;
import cn.yh.springbootjwt.domain.query.ShoppingCartIds;
import cn.yh.springbootjwt.domain.vo.OrdersDtlListVo;
import cn.yh.springbootjwt.service.IOrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/orders")
@Api(tags = "订单管理接口")
public class OrdersController extends BaseController {

    @Autowired
    private IOrdersService ordersService;

    @ApiOperation(value = "用户下订单", notes = "生成当前用户订单，根据购物车ID添加。")
    @PostMapping("/create")
    public AjaxResult createOrders(
            @Validated
            @RequestBody
            ShoppingCartIds shoppingCartIds){
        return toAjax(ordersService.createOrders(shoppingCartIds));
    }

    @GetMapping("/list")
    @ApiOperation(value = "订单列表", notes = "获取当前用户订单列表。")
    @ApiImplicitParam(name = "token", paramType = "header", required = true)
    public AjaxResult<OrdersDtlListVo> selectOrdersList(){
        return AjaxResult.success(ordersService.selectOrdersDtlList());
    }
}
